package labox.innovation.gameserver.model.actor.knownlist;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.gameserver.ai.CtrlIntention;
import labox.innovation.gameserver.ai.L2CharacterAI;
import labox.innovation.gameserver.model.L2Object;
import labox.innovation.gameserver.model.actor.instance.FuzeGuardInstance;
import labox.innovation.gameserver.model.actor.instance.FuzeMonsterInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance.KarmaStat;

/**
 * 守卫型角色的已知列表对象
 * 
 * @author Administrator
 * 
 */
public final class GuardKnownList extends AttackableKnownList {

	private static Logger _log = LoggerFactory.getLogger(GuardKnownList.class.getName());

	// =========================================================
	// Data Field

	// =========================================================
	// Constructor
	public GuardKnownList(FuzeGuardInstance activeChar) {
		super(activeChar);
	}

	// =========================================================
	// Method - Public
	@Override
	public boolean addKnownObject(L2Object object) {
		if (!super.addKnownObject(object))
			return false;

		if (object instanceof FuzePcInstance) {//如果是玩家对象
			//检查玩家的善恶值情况
			FuzePcInstance player = (FuzePcInstance) object;

			if (player.getKarmaStat() == KarmaStat.EVIL) {//如果是邪恶玩家激活AI
				if (_log.isDebugEnabled())
					_log.debug(getActiveChar().getObjectId() + ": PK " + player.getObjectId() + " entered scan range");

				// Set the L2GuardInstance Intention to AI_INTENTION_ACTIVE
				if (getActiveChar().getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)
					getActiveChar().getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
			}
		} else if (getActiveChar().isInActiveRegion() && object instanceof FuzeMonsterInstance) {
			//检查是不是一个有仇恨能力的怪物
			FuzeMonsterInstance mob = (FuzeMonsterInstance) object;

			if (mob.isAggressive()) {//激活AI
				// Set the L2GuardInstance Intention to AI_INTENTION_ACTIVE
				if (getActiveChar().getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)
					getActiveChar().getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
			}
		}

		return true;
	}

	@Override
	public boolean removeKnownObject(L2Object object) {
		if (!super.removeKnownObject(object))
			return false;

		// Check if the _aggroList of the L2GuardInstance is Empty
		if (getActiveChar().noTarget()) {
			//removeAllKnownObjects();

			// Set the L2GuardInstance to AI_INTENTION_IDLE
			L2CharacterAI ai = getActiveChar().getAI();
			if (ai != null)
				ai.setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
		}

		return true;
	}

	// =========================================================
	// Method - Private

	// =========================================================
	// Property - Public
	@Override
	public final FuzeGuardInstance getActiveChar() {
		return (FuzeGuardInstance) _activeObject;
	}
}
